package edu.gyc.hicloud.payment2.controller;



import edu.gyc.hicloud.payment2.model.MyResult;
import edu.gyc.hicloud.payment2.model.Payment;
import edu.gyc.hicloud.payment2.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ls
 * @since 2020-03-14
 */
@RestController
@Slf4j
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("get/{id}")
    public Object get(@PathVariable(name = "id") Long id){
        log.info("*******查询id："+id);
       Payment payment=paymentService.getById(id);
        return new MyResult<Payment>(200,"查询成功，serverPort："+serverPort,payment);

    }
    @PostMapping("/create")
    public MyResult create(@RequestBody Payment payment) {
        log.info("******input payment:"+payment);
        boolean r = paymentService.save(payment);
        log.info("******插入结果："+r);
        if(r){
            return new MyResult(200,"插入数据成功,serverPort:"+serverPort,r);

        }else {
            return new MyResult(444,"插入数据失败");
        }
    }
}

